<template>
  <div>
    <table>
      <tr>
        <td>标题</td>
        <td>图片</td>
        <td>价格</td>
      </tr>
      <tr v-for="i in list">
        <td>{{i.title}}</td>
        <td><img :src="'http://127.0.0.1:8000'+i.img" style="height: 80px;width: 80px"></td>
        <td v-if="uid">￥{{i.price*0.8}}</td>
        <td v-else>￥{{i.price}}</td>
        <td><button @click="add_btn(i.title,i.price*0.8)">预定</button></td>
      </tr>
    </table>
    <button @click="btn">订单</button>
  </div>

</template>

<script>
    export default {
        data(){
          return{
            list:[],
            uid:sessionStorage.getItem('user')
          }
        },
        methods:{
          add_btn(tid,pid){
            if(sessionStorage.getItem('user_id')){
              this.$router.push('/Order/'+tid+'/'+pid)
            }else {
              alert('请登录')
              this.$router.push('/Login')
            }
          },
          btn(){
            this.$router.push('/ShowProduct/'+this.uid)
          }
        },
        created() {
          axios({
            url:'http://127.0.0.1:8000/app02/showproduct/',
            method:'get'
          }).then(res=>{
            console.log(res)
            this.list=res.data
          })
        }
    }
</script>

<style scoped>

</style>